package com.hxd.otc.module.coin_deal.presenter;

import android.support.annotation.NonNull;

import com.hxd.otc.base.BaseBean;
import com.hxd.otc.base.BaseRecyclerPresenter;
import com.hxd.otc.module.coin_deal.adapter.MyEntryOrdersAdapter;
import com.hxd.otc.module.coin_deal.bean.CoinDealResultBean;
import com.hxd.otc.module.coin_deal.bean.DialogCoinTypeBean;
import com.hxd.otc.module.coin_deal.contract.MyEntryOrdersContract;
import com.hxd.otc.module.coin_deal.model.CoinDealModel;
import com.hxd.otc.net.BaseObserver;

import java.util.List;

/**
 * Created by lzy on 2018/7/9 0009.
 * description ${我的挂单 presenter}
 */
public class MyEntryOrdersPresenter extends BaseRecyclerPresenter<MyEntryOrdersContract.View, MyEntryOrdersAdapter, CoinDealResultBean.DataBean> implements MyEntryOrdersContract.Presenter {

    private final CoinDealModel mCoinDealModel;

    public MyEntryOrdersPresenter(MyEntryOrdersContract.View view) {
        super(view);
        mCoinDealModel = CoinDealModel.getInstance();
    }

    @Override
    public void loadData(final boolean isRefresh) {
        mCoinDealModel.getMyEntryOrders(mPageIndex, getPageSize(), new BaseObserver<CoinDealResultBean>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull CoinDealResultBean bean) {
                onLoadDataSuccess(isRefresh, bean.list);
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                onLoadDataFail(isRefresh, errMessage);
            }
        }, mView.<BaseBean<CoinDealResultBean>>bindAutoDispose());
    }

    @Override
    public void deleteEntryOrders(final String id) {
        mCoinDealModel.deleteEntryOrders(id, new BaseObserver<String>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull String s) {
                mView.deleteEntryOrdersSuccess(id, msg);
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.showToast(errMessage);
            }
        }, mView.<BaseBean<String>>bindAutoDispose());
    }

    @Override
    public void getCoinType() {
        mCoinDealModel.getCoinType(new BaseObserver<List<DialogCoinTypeBean>>() {
            @Override
            public void onNext(String msg, List<DialogCoinTypeBean> coinTypeBeans) {
                mView.getCoinType(coinTypeBeans);
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {

                mView.showToast(errMessage);
            }

        }, mView.<BaseBean<List<DialogCoinTypeBean>>>bindAutoDispose());
    }
}
